package com.heima.kafka.controller;


import com.alibaba.fastjson.JSON;
import com.heima.kafka.pojos.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @Autowired
    KafkaTemplate<String, String> kafkaTemplate;

    @GetMapping("/hello")
    public String hello() {
//        kafkaTemplate.send("topic1", "你个小赤佬");

        User user = new User("夫哥哥", 25);
        kafkaTemplate.send("topic1", JSON.toJSONString(user));
        return "发送成功，去看控制台吧！";
    }


}
